<template>
	<div class="allcontainer" v-loading="loading">
		<!-- <div class="h2">积分申请管理（班主任）</div> -->
		<div class="bg-white">
		<div id="components-form-demo-advanced-search">
			<a-form class="ant-advanced-search-form home-form"  :form="form" @submit="handleSearch">
				<a-row :gutter="24">
					<a-col :span="8">
						<a-form-item label="我辅导的班级">
							<a-select :allowClear="true" v-decorator="['classID']" placeholder="全部"
								optionFilterProp="children" showSearch @change="ChangeClass">
								<a-select-option v-for="(item, index) in ClassData" :key="index" :value="item.ID">
									{{ item.Name }}/{{item.DepaerName}}
								</a-select-option>
							</a-select>
						</a-form-item>
					</a-col>
					<a-col :span="12" style="margin-top:2px;">
						<a-button type="primary" html-type="submit" class="btn1">搜索</a-button>
						<a-button @click="handleReset" class="btn2">重置</a-button>
						<a-button type="primary" class="btn" v-if="classID!=''" @click="classSure" >批量确认</a-button>
					</a-col>
				</a-row>
			</a-form>
		</div>
		<div class="table">
			<el-table stripe ref="singleTable" :data="data" highlight-current-row style="width: 100%"
				@expand-change="hangClick">
				<el-table-column type="expand" prop="children">
					<template scope="scope">
						<el-table :data="scope.row.CreditApplyData">
							<el-table-column prop="No" label="编号" min-width="100" align="center"></el-table-column>
							<el-table-column prop="Title" label="名称" min-width="100"></el-table-column>
							<el-table-column prop="Name" label="状态/活动名称" min-width="240">
								<template slot-scope="scope">
									<a-tag color="red">{{ scope.row.StateName}}</a-tag>
									{{ scope.row.ActivityTypeName }}
								</template>
							</el-table-column>
							<el-table-column prop="ActivityTypePrizeName" label="奖项名称/类型" min-width="140"
								show-overflow-tooltip align="center">
								<template slot-scope="scope">
									{{ scope.row.ActivityTypePrizeName}} {{ scope.row.MemberTypeName}}
									</template>
							</el-table-column>
							<el-table-column prop="Score" label="分值" min-width="60" show-overflow-tooltip align="center">
							</el-table-column>
							<el-table-column prop="AddTime" label="申请时间" min-width="120" align="center"></el-table-column>
							<el-table-column prop="IsEnable" label="操作" width="188" fixed="right">
								<template slot-scope="scope">
									<div class="user-btn user-btn-auto">
										<span class="modify" @click="modifyList(scope.row, 'modify')">修改</span>
										<span class="reject" @click="canceladmin(scope.row,4)">驳回</span>
										<span class="file" @click="seeList(scope.row, 'UserApplyEnclosure')">附件</span>
									</div>
								</template>
							</el-table-column>
						</el-table>
					</template>
				</el-table-column>
				<el-table-column type="index" label="序号" width="60" fixed="left" align="center"></el-table-column>
				<el-table-column prop="TotalScore" label="申请人" min-width="100" align="center">
					<template slot-scope="scope">
						<a-tag color="green">{{ scope.row.UserNo }}/{{ scope.row.UserName }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column prop="ClassName" label="班级" min-width="100" align="center"></el-table-column>
				<el-table-column prop="DepartName" label="部门/学院" min-width="100" align="center"></el-table-column>
				<el-table-column prop="TotalScore" label="总分" min-width="100" align="right"></el-table-column>
				<!-- <el-table-column prop="IsEnable" label="操作" min-width="100" fixed="right">
					<template slot-scope="scope">
						<i title="删除" v-if="!scope.row.IsManager" class="iconfont icon-delete1" style="color: red;" @click="deletemember(scope.row)"></i>
						<i title="详情" v-if="scope.row.IsManager && ChairmanNo == UserInfo.UserNo" class="iconfont icon-chakan" style="color: #1890FF;"
						 @click="detail(scope.row,1)"></i>
						<i title="修改权限" v-if="scope.row.IsManager && ChairmanNo == UserInfo.UserNo" class="iconfont icon-editor1" style="color: #1890FF;"
						 @click="detail(scope.row,2)"></i>
						<i title="设为管理员" v-if="!scope.row.IsManager && ChairmanNo == UserInfo.UserNo" class="iconfont icon-guanliyuan1"
						 style="color: deeppink;" @click="detail(scope.row,3)"></i>
						<i title="取消管理员" v-if="scope.row.IsManager && ChairmanNo == UserInfo.UserNo" class="iconfont icon-assist-cancel"
						 style="color: red;" @click="canceladmin(scope.row,4)"></i>
					</template>
				</el-table-column> -->
			</el-table>
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:current-page="pagination.currentPage" :page-sizes="pagination.pageSizeOptions"
				:page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper"
				:total="pagination.total"></el-pagination>
		</div>
		</div>
		<add :ActivityTypePrizeTypeList="ActivityTypePrizeTypeList" :ActivityMemberTypeList="ActivityMemberTypeList"
			:ActivityTypeData="ActivityTypeData" :text="text" :DepartCodeList="DepartCodeList" :TypeIDList="TypeIDList"
			v-show="addIf" @closeFun="closeFun">
		</add>
		<!-- <detail :approvalType="4" :time="time" :text="text" :ID="ClubID" :linktype="linktype" v-show="showModal" @closeFun="closeFun(1)"></detail> -->
	</div>
</template>

<script>
	import add from './add';
	import Func from '@/utils/func';
	import Cache from '@/utils/cache';
	import {
		UserCreditApplyTeacherDoGetList,
		UserCreditApplyTeacherDoGetClassList,
		UserCreditApplyTeacherDoReturn,
		UserCreditApplyTeacherDoConfirm
	} from '@/api/follow';
	// import detail from './detail';
	const data = [];
	export default {
		components: {
			add
			//	detail
		},
		data() {
			return {
				currentExpandRow:[],
				CreditSessionData: [],
				SemesterList: [],
				stateData: [{
					ID: '1',
					Name: "状态值未给"
				}, ],
				applyTypeData: [{
						ID: '1',
						Name: "参与申请"
					},
					{
						ID: '2',
						Name: "获奖申请"
					}
				],
				ActivityTypePrizeTypeList: [],
				ActivityMemberTypeList: [],
				ActivityTypeData: [],
				resourceC: [],
				ClassData: [],
				data,
				form: this.$form.createForm(this, {
					name: 'advanced_search'
				}),
				pagination: {
					currentPage: 1,
					pageSize: this.global.pageSize,
					pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
					showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
				},
				addIf: false,
				text: {},
				visible: false,
				confirmLoading: false,
				itemId: '',
				departmentList: [],
				worklist: [],
				loading: false,
				values: {},
				pages: {
					pageIndex: 1,
					pageSize: 20
				},
				tableHeight: parseFloat(window.innerHeight - 160),
				TypeIDList: [],
				DepartCodeList: [],
				ProjectIDList: [],
				ishaveid: true,
				selectList: {},
				showModal: false,
				UserInfo: Cache.get('myInfo'),
				ChairmanNo: this.$route.query.ChairmanNo,
				linktype: 1,
				ClubID: this.$route.query.ID,
				visible: false,
				deletelist: {},
				time: '',
				classID: "",
			};
		},
		computed: {},
		created() {
			//this.getList();
			this.getOtherList()
		},
		mounted() {},
		methods: {
			classSure(){
				let that = this;
				if(this.classID!=''){
					this.$confirm({
						title: '提示',
						content: `当前操作会将当前班级申请确认，是否继续操作？`,
						okText: '确认',
						cancelText: '取消',
						async onOk() {
							let data = {};
							data.classID=that.classID
							let res = await UserCreditApplyTeacherDoConfirm(data);
							if (res.data.code == 0) {
								that.getList();
							} 
							 that.$message.success('设置成功')
							// that.$message.success('设置成功'+res.data.Success,'失败'+res.data.Error);
						}
					});
				}else{
					that.$message.error('请选择班级');
				}
				
			},
			seeList(text,name){
				this.$router.push({
					name: name,
					query: {
						ID: text.ID,
						Name: text.Name,
					}
				});
			},
			hangClick(e) {
				// this.resourceC=[];
				// this.resourceC = e.CreditApplyData;
			},
			ChangeClass(e) {
				this.classID = e;
				this.getList()
			},
			async getOtherList() {
				let res = await UserCreditApplyTeacherDoGetClassList(data);
				this.ClassData = res.data.data;
			},
			// setadmin(text) {
			// 	let data={}
			// 	data.
			// 	let res = await DoAddUserClubMember(data)
			// },
			canceladmin(text) {
				let that = this;
				this.$confirm({
					title: '提示',
					content: `您确定驳回该申请吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {};
						data.ID=text.ID
						let res = await UserCreditApplyTeacherDoReturn(data);
						if (res.data.code == 0) {
							that.getList();
							that.$message.success(res.data.msg);
						} else {
							that.$message.error(res.data.msg);
						}
					}
				});
			},
			handleCancel(e) {
				this.visible = false;
				this.getList();
			},
			deletemember(text) {
				// this.visible = true
				// this.deletelist = text
				let that = this;
				this.$confirm({
					title: '提示',
					content: `您确定删除该用户吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {};
						data.id = text.ID;
						let res = await DoDeleteUserClubMember(data);
						if (res.data.code == 0) {
							that.getList();
							that.$message.success(res.data.msg);
						} else {
							that.$message.error(res.data.msg);
						}
					}
				});
			},
			detail(text, type) {
				this.linktype = type;
				this.text = text;
				this.time = new Date();
				this.showModal = true;
			},
			handleChange(val) {
				this.currentRow = val;
				if (val.ID) {
					this.ishaveid = false;
					this.selectList = val;
				} else {
					this.ishaveid = true;
				}
			},
			handleSearch(e) {
				if (this.classID == '') {
					this.$message.error('请先选择班级');
					return
				}
				e.preventDefault();
				this.form.validateFields((error, values) => {
					this.pagination.currentPage = 1;
					this.values = values;
					this.getList();
				});
			},
			handleReset() {
				this.form.resetFields();
				this.values = {};
				this.getList();
			},
			handleSizeChange(val) {
				this.pagination.pageSize = val;
				this.getList();
			},
			handleCurrentChange(val) {
				this.pagination.currentPage = val;
				this.getList();
			},
			async getList() {
				this.loading = true;
				let data = {};
				if (this.values) {
					data = this.values;
				}
				data.classID = this.classID;
				data.pageIndex = this.pagination.currentPage;
				data.pageSize = this.pagination.pageSize;
				data.state = 2
				let res = await UserCreditApplyTeacherDoGetList(data);
				this.loading = false;
				this.data = res.data.data;
				// const pagination = {
				// 	...this.pagination
				// };
				// pagination.total = res.data.pageInfo.TotalItemCount;
				// this.pagination = pagination;
			},
			addList() {
				this.text = {};
				this.addIf = !this.addIf;
			},
			modifyList(text) {
				text = Object.assign(text, {
					time: new Date()
				});
				this.addIf = !this.addIf;
				this.text = text;
			},
			closeFun(index) {
				this.addIf=false;
				this.showModal = false;
				this.getList();
			}
		}
	};
</script>
<style scoped lang="less">
	.home-form{
		/deep/.ant-form-item-label{
			width: 110px;
		}
	}
</style>

